# Prize controller controls application prizes 
# In 13wins, the user may win a prize if they reach a 13-15 winstreak

class PrizesController < ApplicationController
  # User selects a prize
  # (prize change only allowed when the streak required for the prize is less than the current streak of the user)
  def select
    @prize = Prize.find params[:id]
    if current_user.winstreak.streak_count.to_i >= @prize.streak
      flash[:error] = "You cannot change to this prize."
    else
      current_user.prize = @prize
      current_user.save
      flash[:notice] = "You have selected the #{@prize.name}"
    end
    redirect_to bets_path
  end

end
